package com.jsp.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.jsp.bean.VehicleBean;
import com.jsp.util.DBUtil;

public class VehicleDao {
	
	public  VehicleBean insert(VehicleBean vehicle) throws SQLException {
		Connection con=DBUtil.getConnection();
		String sql="insert into vehicleinformation"
				+ "(plateNumber,models,productDate,driverInformation,state)"
				+ "values (?,?,?,?,?)";
		PreparedStatement state =con.prepareStatement(sql);
		state.setString(1, vehicle.getPlateNumber());
		state.setString(2, vehicle.getModels());
		state.setString(3, vehicle.getProductDate());
		state.setString(4, vehicle.getDriverInformation());
		state.setString(5, vehicle.getState());
		state.executeUpdate();
		state.close();
		con.close();
		return vehicle;
		
	}
	
		
	
	
	public VehicleBean update(VehicleBean vehicle) throws SQLException {
		Connection con=DBUtil.getConnection();
		String sql="update vehicleinformation set "
				+ "id=?,plateNumber=?,models=?,productDate=?,"
				+ "driverInformation=?,state=? where id=?";
		PreparedStatement state =con.prepareStatement(sql);
		state.setString(1, vehicle.getId());
		state.setString(2, vehicle.getPlateNumber());
		state.setString(3, vehicle.getModels());
		state.setString(4, vehicle.getProductDate());
		state.setString(5, vehicle.getDriverInformation());	
		state.setString(6, vehicle.getState());
		state.setString(7, vehicle.getId());
		state.executeUpdate();
		state.close();
		con.close();
		return vehicle;
	}
	public VehicleBean detele(VehicleBean vehicle) throws SQLException {
		Connection con=DBUtil.getConnection();
		String sql="delete from vehicleinformation where id=?";
		PreparedStatement state =con.prepareStatement(sql);
		state.setString(1, vehicle.getId());
		state.executeUpdate();
		state.close();
		con.close();
		return vehicle;
	}
	
	
}
